//
//  BindingViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/5/8.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "BindingViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "UserProtocolViewController.h"
#import "MainLineViewController.h"
#import "LoginViewController.h"
#import "BangDinView1.h"
#import "YoungAllData.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "FinishWithDrawViewController.h"
#import "PickerView.h"
#import "GMDCircleLoader.h"

#import "AFNetworking.h"
#import "EncryptionData.h"

#import "BangdinTableViewCell.h"

@interface BindingViewController ()<UITextFieldDelegate,UIScrollViewDelegate,UIPickerViewDataSource,UIPickerViewDelegate,YoungDelegate,UITableViewDataSource,UITableViewDelegate>
{
    UIView *views;
    UIView *alertView;
    UIPickerView *_picker;
    NSArray *pickerArray;
    NSInteger _select;//选择
    UITableView *zTableView;
    UIButton *zPickerBtn;
    UIButton *_getPasswordBut;
    UILabel *_timeLabel;
    NSTimer *zTimer;
    UITextField *_phoneNumber;
    UITextField *_passwd;
    BangDinView1 *_bangdin;
    UIView *_zScrollView;
}
@property(nonatomic,retain)NSString *zPID;
@property(nonatomic,retain)NSString *zCID;
@property(nonatomic,retain)NSString *zBackID;
@property(nonatomic,retain)NSMutableArray  *zArrayData;
@property(nonatomic,retain)NSMutableArray *zBankList;
@property(nonatomic,retain)NSMutableDictionary *zBankDic;
@property(nonatomic,assign)NSInteger zIndex;

@property(nonatomic,retain)NSString *merOrderId;
@property(nonatomic,retain)NSString *phoneNo;
@property(nonatomic,retain)NSString *phoneToken;
@property(nonatomic,retain)UITableView *mytableview;

@end
#define Province 0 //省
#define City 1  //市
#define Qu 2   //区
@implementation BindingViewController
@synthesize zCID,zPID,zArrayData,zBankList,zBackID,zBankDic,zProvinceIndex,zCityIndex,zZhengJianIndex,zIndex,zName,zNumber,zZhengType,isWhere;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;
    
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    [self initNav];
    navTitle.text = @"绑定银行卡";

    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(errorBind) name:@"errorBind" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(bankBut:) name:@"bankBut" object:nil];
    zPID = @"0";
    zCID = @"0";
    zBackID = @"0";
    
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];

    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    
    NSString *str;
    str = @"0";
    [data gainBankList:str];
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [self.view addGestureRecognizer:singleTapGestureRecognizer];
    zProvinceIndex = 0;
    zCityIndex = 0;
    zZhengJianIndex = 0;
    
    self.mytableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64-50) style:UITableViewStylePlain];
    self.mytableview.delegate = self;
    self.mytableview.dataSource = self;
    [self.view addSubview:self.mytableview];
    [self createTableViewHeadView];
    [self createTableFoodView];
    
    
}

#pragma mark 点击银行按钮获取到银行ID
- (void)bankBut:(NSNotification *)sender{
    
    NSDictionary * dic = sender.userInfo;
    NSString *banID = dic[@"BankId"];
    UIButton *butSender = dic[@"button"];
    zBackID = banID;

    NSArray *cells = [self.mytableview visibleCells];
    for (BangdinTableViewCell *cell in cells) {
        NSArray *viewsa = cell.contentView.subviews;
        for (int i = 0; i< viewsa.count; i++) {
            UIView *view = viewsa[i];
            if ([[view class] isSubclassOfClass:[UIButton class]]) {
                if ([butSender isEqual:view]) {
                    [butSender.layer setBorderWidth:1.0f];
                    [butSender.layer setBorderColor:[UIColor redColor].CGColor];
                } else{
                
                    [view.layer setBorderWidth:1.0f];
                    [view.layer setBorderColor:[UIColor grayColor].CGColor];
                }
            }
        }
    }
    
}
#pragma mark - 返回
-(void)clickBackBtn{
    if ([isWhere isEqualToString:@"1"]) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }}
-(void)singleTap{
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curFrame=CGRectMake(0, 0, self.view.width, self.view.height);
        self.view.frame=curFrame;
    }];
    self.tabBarController.tabBar.hidden = NO;
    UITextField *text1 = (UITextField *)[self.view viewWithTag:500];
    UITextField *text2 = (UITextField *)[self.view viewWithTag:501];
    UITextField *text3 = (UITextField *)[self.view viewWithTag:502];
    UITextField *text4 = (UITextField *)[self.view viewWithTag:503];
    [text1 resignFirstResponder];
    [text2 resignFirstResponder];
    [text3 resignFirstResponder];
    [text4 resignFirstResponder];
    [_passwd resignFirstResponder];
    [_phoneNumber resignFirstResponder];
}
#pragma mark - errorBind
-(void)errorBind{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 银行列表回调
-(void)bankList:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
//    zBankDic = [[NSMutableDictionary alloc]initWithDictionary:[sign objectForKey:@"data"]];
        zBankList = [[NSMutableArray alloc] initWithArray:[sign objectForKey:@"data"]];
//    [self initUI];
        [self.mytableview  reloadData];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = zBankList[indexPath.row];
    NSArray *bankArry = dic[@"BankList"];
    
    NSInteger zCount = bankArry.count/3;
    NSLog(@"%lu",bankArry.count%3);
    if (([bankArry count]%3) != 0) {
        zCount += 1;
    }
    
    return zCount*45+20;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return zBankList.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *indent = @"cell";
    BangdinTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indent];
    if (cell == nil) {
        cell = [[BangdinTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indent];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dic = zBankList[indexPath.row];
    [cell sdataUI:dic];
    
//    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
//    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
//    
//    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
//    
//    cell.backgroundColor= [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
    
    return cell;
}
#pragma mark 创建tableviewFoodView
- (void)createTableFoodView{
    UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 133)];
    //手机号码
    _phoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, pView.width-20, 40)];
    _phoneNumber.layer.borderWidth = 1.0;
    _phoneNumber.delegate = self;
    _phoneNumber.layer.borderColor = BackColor.CGColor;
    _phoneNumber.keyboardType = UIKeyboardTypeNumberPad;
    _phoneNumber.backgroundColor = [UIColor whiteColor];
    _phoneNumber.placeholder = @"手机号码";
    [pView addSubview:_phoneNumber];
    
    //验证码
    _passwd = [[UITextField alloc] initWithFrame:CGRectMake(10, _phoneNumber.bottom, pView.width/2.0-10, 40)];
    _passwd.layer.borderWidth = 1.0;
    _passwd.delegate = self;
    _passwd.keyboardType = UIKeyboardTypeNumberPad;
    _passwd.layer.borderColor = BackColor.CGColor;
    _passwd.backgroundColor = [UIColor whiteColor];
    _passwd.placeholder = @"验证码";
    [pView addSubview:_passwd];
    
    //获取验证码按钮
    _getPasswordBut = [[UIButton alloc] initWithFrame:CGRectMake(_passwd.right, _phoneNumber.bottom, pView.width/2.0-10, 40)];
    [_getPasswordBut setTitle:@"获取验证码" forState:UIControlStateNormal];
    [_getPasswordBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _getPasswordBut.layer.borderWidth = 1.0;
    _getPasswordBut.layer.borderColor = BackColor.CGColor;
    _getPasswordBut.backgroundColor = [self colorWithHexString:@"#EB2F6C"];;
    [_getPasswordBut addTarget:self action:@selector(clickRBtn:) forControlEvents:UIControlEventTouchUpInside];
    [pView addSubview:_getPasswordBut];
    
    //倒计时
    _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_passwd.right, _phoneNumber.bottom, pView.width/2.0-10, 40)];
    _timeLabel.layer.borderWidth = 1.0;
    _timeLabel.layer.borderColor = BackColor.CGColor;
    _timeLabel.textColor = [UIColor whiteColor];
    _timeLabel.textAlignment = NSTextAlignmentCenter;
    _timeLabel.backgroundColor = [UIColor colorWithRed:243/255.0 green:0 blue:86/255.0 alpha:1];
    _timeLabel.hidden = YES;
    [pView addSubview:_timeLabel];
    
    UIButton *downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    downBtn.frame = CGRectMake(10, _passwd.bottom+10, pView.width-20, 43);
    [downBtn setBackgroundImage:[UIImage imageNamed:@"bangdingyinhangka-lijibangding"] forState:UIControlStateNormal];
    [downBtn addTarget:self action:@selector(clickBang) forControlEvents:UIControlEventTouchUpInside];
    [pView addSubview:downBtn];
    self.mytableview.tableFooterView = pView;
}
#pragma mark 创建tableviewHeadView
- (void)createTableViewHeadView{
    _zScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, 340)];
    [self.view addSubview:_zScrollView];

    _bangdin = [[[NSBundle mainBundle] loadNibNamed:@"GeRen_xibs" owner:self options:nil] objectAtIndex:9];
    _bangdin.layer.borderColor = BackColor.CGColor;
    _bangdin.layer.borderWidth = 1,0;
    _bangdin.frame = CGRectMake(10, 20, SCREEN_WIDTH-20, 280);
    [_zScrollView addSubview:_bangdin];
    
    _bangdin.zBankText.delegate = self;
    _bangdin.zName.delegate = self;
    _bangdin.zBankName.delegate = self;
    _bangdin.zDocumentsNumber.delegate = self;
    _bangdin.zBankText.tag = 500;
    _bangdin.zBankText.keyboardType = UIKeyboardTypeNumberPad;
    
    _bangdin.zName.tag = 501;
    _bangdin.zBankName.tag = 502;
    _bangdin.zDocumentsNumber.tag = 503;
    _bangdin.zDocumentsNumber.keyboardType = UIKeyboardTypeNumberPad;
    
    [_bangdin.zType addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zType.tag = 400;
    [_bangdin.zProvince addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zProvince.tag = 401;
    [_bangdin.zCity addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zCity.tag = 402;
    [_bangdin.zBankType addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zBankType.tag = 403;
    
    
    [_bangdin.provinceBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.provinceBut.tag = 401;
    [_bangdin.cityBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.cityBut.tag = 402;
    [_bangdin.quBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.quBut.tag = 403;
    
    
    if ([isWhere isEqualToString:@"3"]) {
        _bangdin.zDocumentsNumber.userInteractionEnabled = YES;
        
    }else{
        _bangdin.zDocumentsNumber.userInteractionEnabled = NO;
        _bangdin.zDocumentsNumber.text = zNumber;
        _bangdin.zName.text = zName;
        _bangdin.zName.userInteractionEnabled = NO;
        _bangdin.quBut.userInteractionEnabled = NO;
        _bangdin.quBut.hidden = YES;
        _bangdin.zBankType.userInteractionEnabled = NO;
        [_bangdin.zBankType setTitle:zZhengType forState:UIControlStateNormal];
        [_bangdin.zBankType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    
    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-58-120, _bangdin.bottom, 120, 20)];
    
    leftLabel.text = @"点击绑定,即视为同意";
    leftLabel.textColor  = [self colorWithHexString:@"#A6A6A6"];
    leftLabel.textAlignment = NSTextAlignmentRight;
    leftLabel.font = [UIFont systemFontOfSize:12];
    [_zScrollView addSubview:leftLabel];
    
    UIButton *userBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    userBtn.frame = CGRectMake(leftLabel.right, leftLabel.top, 48, 20);
    [userBtn setTitle:@"用户协议" forState:UIControlStateNormal];
    [userBtn setTitleColor:[self colorWithHexString:@"#67A8DB"] forState:UIControlStateNormal];
    userBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [userBtn addTarget:self action:@selector(clickUserBtn) forControlEvents:UIControlEventTouchUpInside];
    [_zScrollView addSubview:userBtn];
    
    
    UILabel *choose = [[UILabel alloc]initWithFrame:CGRectMake(10, leftLabel.bottom, 120, 20)];
    choose.text = @"选择银行";
    choose.textColor  = [UIColor blackColor];
    choose.textAlignment = NSTextAlignmentLeft;
    choose.font = [UIFont systemFontOfSize:14];
    [_zScrollView addSubview:choose];
    
    
    self.mytableview.tableHeaderView = _zScrollView;
}


static int btnTag = 0;
#pragma mark - initUI
-(void)initUI{
    /*
//    UIButton *belowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    belowBtn.frame = CGRectMake(0,SCREEN_HEIGHT-(0.15625*SCREEN_WIDTH) , SCREEN_WIDTH, 0.15625*SCREEN_WIDTH);
//    [belowBtn setBackgroundImage:[UIImage imageNamed:@"信息_06"] forState:UIControlStateNormal];
//    [belowBtn addTarget:self action:@selector(backGo) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:belowBtn];
    
    _zScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,navView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-0.15625*SCREEN_WIDTH-20-50)];
    //zScrollView.backgroundColor = [UIColor redColor];
//    _zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*3);
    _zScrollView.userInteractionEnabled = YES;
    [self.view addSubview:_zScrollView];

    _bangdin = [[[NSBundle mainBundle] loadNibNamed:@"GeRen_xibs" owner:self options:nil] objectAtIndex:9];
//    bangdin.backgroundColor = [UIColor blueColor];
    _bangdin.layer.borderColor = BackColor.CGColor;
    _bangdin.layer.borderWidth = 1,0;
    _bangdin.frame = CGRectMake(10, 20, SCREEN_WIDTH-20, 280);
    [_zScrollView addSubview:_bangdin];
    
    _bangdin.zBankText.delegate = self;
    _bangdin.zName.delegate = self;
    _bangdin.zBankName.delegate = self;
    _bangdin.zDocumentsNumber.delegate = self;
    _bangdin.zBankText.tag = 500;
    _bangdin.zBankText.keyboardType = UIKeyboardTypeNumberPad;

    _bangdin.zName.tag = 501;
    _bangdin.zBankName.tag = 502;
    _bangdin.zDocumentsNumber.tag = 503;
    _bangdin.zDocumentsNumber.keyboardType = UIKeyboardTypeNumberPad;
    
    [_bangdin.zType addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zType.tag = 400;
    [_bangdin.zProvince addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zProvince.tag = 401;
    [_bangdin.zCity addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zCity.tag = 402;
    [_bangdin.zBankType addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.zBankType.tag = 403;
    

    [_bangdin.provinceBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.provinceBut.tag = 401;
    [_bangdin.cityBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.cityBut.tag = 402;
    [_bangdin.quBut addTarget:self action:@selector(clickType:) forControlEvents:UIControlEventTouchUpInside];
    _bangdin.quBut.tag = 403;
  
    
    if ([isWhere isEqualToString:@"3"]) {
        _bangdin.zDocumentsNumber.userInteractionEnabled = YES;
        
    }else{
        _bangdin.zDocumentsNumber.userInteractionEnabled = NO;
        _bangdin.zDocumentsNumber.text = zNumber;
        _bangdin.zName.text = zName;
        _bangdin.zName.userInteractionEnabled = NO;
        _bangdin.quBut.userInteractionEnabled = NO;
        _bangdin.quBut.hidden = YES;
        _bangdin.zBankType.userInteractionEnabled = NO;
        [_bangdin.zBankType setTitle:zZhengType forState:UIControlStateNormal];
        [_bangdin.zBankType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

    
    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-58-120, _bangdin.bottom, 120, 20)];
    
    leftLabel.text = @"点击绑定,即视为同意";
    leftLabel.textColor  = [self colorWithHexString:@"#A6A6A6"];
    leftLabel.textAlignment = NSTextAlignmentRight;
    leftLabel.font = [UIFont systemFontOfSize:12];
    [_zScrollView addSubview:leftLabel];
    
    UIButton *userBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    userBtn.frame = CGRectMake(leftLabel.right, leftLabel.top, 48, 20);
    [userBtn setTitle:@"用户协议" forState:UIControlStateNormal];
    [userBtn setTitleColor:[self colorWithHexString:@"#67A8DB"] forState:UIControlStateNormal];
    userBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [userBtn addTarget:self action:@selector(clickUserBtn) forControlEvents:UIControlEventTouchUpInside];
    [_zScrollView addSubview:userBtn];
    
    
    UILabel *choose = [[UILabel alloc]initWithFrame:CGRectMake(10, leftLabel.bottom, 120, 20)];
    choose.text = @"选择银行";
    choose.textColor  = [UIColor blackColor];
    choose.textAlignment = NSTextAlignmentLeft;
    choose.font = [UIFont systemFontOfSize:14];
    [_zScrollView addSubview:choose];
    
//    UILabel *xian1 = [[UILabel alloc]initWithFrame:CGRectMake(10, choose.bottom, 120, 20)];
//    xian1.text = @"";
//    xian1.textColor  = [UIColor grayColor];
//    xian1.textAlignment = NSTextAlignmentLeft;
//    xian1.font = [UIFont systemFontOfSize:12];
//    [_zScrollView addSubview:xian1];
//    
//    UILabel *xian3 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-160, choose.bottom, 150, 20)];
//    xian3.text = @"";
//    xian3.textColor  = [UIColor grayColor];
//    xian3.textAlignment = NSTextAlignmentRight;
//    xian3.font = [UIFont systemFontOfSize:12];
//    [_zScrollView addSubview:xian3];
    
    for (int i = 0; i< zBankList.count; i++){
        NSDictionary *zbankDic = zBankList[i];
        NSArray *bankArry = zbankDic[@"BankList"];
        NSInteger zCount = bankArry.count/3;
        NSLog(@"%lu",zBankList.count%3);
        if (([bankArry count]%3) != 0) {
            zCount += 1;
        }
        
        UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(0, choose.bottom+i*((zCount*35)+25), SCREEN_WIDTH, (zCount*35)+25)];
        CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
        CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
        
        CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
        
        aview.backgroundColor= [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
        [_zScrollView addSubview:aview];
        
        
    }
    
    
    
    
    
/*
    
    int   btnTag11 = 1;
    CGFloat y = 0;
    for (int i = 0; i< zBankList.count; i++) {
        NSDictionary *zbankDic = zBankList[i];
        NSArray *bankArr = zbankDic[@"BankList"];
        
        
        NSInteger zCount = bankArr.count/3;
        NSLog(@"%lu",zBankList.count%3);
        if (([bankArr count]%3) != 0) {
            zCount += 1;
        }
        
        
        
        if (i==0) {
            y =choose.bottom;
        } else{
        
             UIView *labelView = [_zScrollView viewWithTag:btnTag11-1];
            y = labelView.bottom;
            
        }
        NSLog(@"顺序=====%@",zbankDic[@"DayLimit"]);
        UILabel *choose = [[UILabel alloc]initWithFrame:CGRectMake(10, y , SCREEN_WIDTH/2.0-20, 20)];
        choose.text = [NSString stringWithFormat:@"单笔限额%@",zbankDic[@"DayLimit"]];
        choose.textColor  = [UIColor blackColor];
        choose.textAlignment = NSTextAlignmentLeft;
        choose.font = [UIFont systemFontOfSize:14];
        choose.tag = btnTag11;
        ++btnTag11;
        [_zScrollView addSubview:choose];
        
        UILabel *choose2 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2.0-10, leftLabel.bottom+40 + i*((bankArr.count/3 +1)*40), SCREEN_WIDTH/2.0-20, 20)];
        choose2.text = [NSString stringWithFormat:@"每日限额%@",zbankDic[@"SingleLimit"]];
        choose2.textColor  = [UIColor blackColor];
        choose2.textAlignment = NSTextAlignmentRight;
        choose2.font = [UIFont systemFontOfSize:14];
        choose.tag = i+1;
        [_zScrollView addSubview:choose2];
 
         btnTag = 0;
        
      

        for (int j = 0; j< zCount; j++) {
            
            int num = 0;
            if (bankArr.count == 1) {
                num = 1;
            } else if (bankArr.count == 2){
                num = 2;
            } else{
            
                num = 3;
            }
           
            for (int h = 0; h < num; h++) {

//
                NSDictionary *dica = bankArr[btnTag];
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                if (SCREEN_WIDTH == 320) {
                    
                    UIView *labelView = [_zScrollView viewWithTag:i+1];
                    
                    
                    btn.frame = CGRectMake(10+102.5*h,labelView.bottom+100+5+j*40 , 95, 35);
                }
                [btn.layer setBorderWidth:1.0f];
                [btn.layer setBorderColor:[UIColor grayColor].CGColor];
                
//                [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:dic[@"LogoPath"]] forState:UIControlStateNormal];
                [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:dica[@"LogoPath"]] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
                [_zScrollView addSubview:btn];
                btn.tag = btnTag+700;
                btnTag++;
                if (btnTag == [bankArr count]) {
                    break;
                }
            }
        }

    
    */
    
 
//    UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(10, choose.bottom+270, SCREEN_WIDTH-20, 133)];
//    [_zScrollView addSubview:pView];
//   //手机号码
//    _phoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, pView.width, 40)];
//    _phoneNumber.layer.borderWidth = 1.0;
//    _phoneNumber.delegate = self;
//    _phoneNumber.layer.borderColor = BackColor.CGColor;
//    _phoneNumber.keyboardType = UIKeyboardTypeNumberPad;
//    _phoneNumber.backgroundColor = [UIColor whiteColor];
//    _phoneNumber.placeholder = @"手机号码";
//    [pView addSubview:_phoneNumber];
//    
//    //验证码
//    _passwd = [[UITextField alloc] initWithFrame:CGRectMake(0, _phoneNumber.bottom, pView.width/2.0, 40)];
//    _passwd.layer.borderWidth = 1.0;
//    _passwd.delegate = self;
//    _passwd.keyboardType = UIKeyboardTypeNumberPad;
//    _passwd.layer.borderColor = BackColor.CGColor;
//    _passwd.backgroundColor = [UIColor whiteColor];
//    _passwd.placeholder = @"验证码";
//    [pView addSubview:_passwd];
//    
//    //获取验证码按钮
//    _getPasswordBut = [[UIButton alloc] initWithFrame:CGRectMake(_passwd.right, _phoneNumber.bottom, pView.width/2.0, 40)];
//    [_getPasswordBut setTitle:@"获取验证码" forState:UIControlStateNormal];
//    [_getPasswordBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    _getPasswordBut.layer.borderWidth = 1.0;
//    _getPasswordBut.layer.borderColor = BackColor.CGColor;
//    _getPasswordBut.backgroundColor = [UIColor colorWithRed:243/255.0 green:0 blue:86/255.0 alpha:1];
//    [_getPasswordBut addTarget:self action:@selector(clickRBtn:) forControlEvents:UIControlEventTouchUpInside];
//    [pView addSubview:_getPasswordBut];
//    
//    //倒计时
//    _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_passwd.right, _phoneNumber.bottom, pView.width/2.0, 40)];
//    _timeLabel.layer.borderWidth = 1.0;
//    _timeLabel.layer.borderColor = BackColor.CGColor;
//    _timeLabel.textColor = [UIColor whiteColor];
//    _timeLabel.textAlignment = NSTextAlignmentCenter;
//    _timeLabel.backgroundColor = [UIColor colorWithRed:243/255.0 green:0 blue:86/255.0 alpha:1];
//    _timeLabel.hidden = YES;
//    [pView addSubview:_timeLabel];
//    
//    UIButton *downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    downBtn.frame = CGRectMake(0, _passwd.bottom+10, pView.width, 43);
//    [downBtn setBackgroundImage:[UIImage imageNamed:@"bangdingyinhangka-lijibangding"] forState:UIControlStateNormal];
//    [downBtn addTarget:self action:@selector(clickBang) forControlEvents:UIControlEventTouchUpInside];
//    [pView addSubview:downBtn];
//    }
    
    
 
    
    
    /*
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"LevelID"] isEqualToString:@"2"]) {
        NSInteger dan1 = [[[zBankDic objectForKey:@"Boss"] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDan1 = dan1/10000;
        xian1.text = [NSString stringWithFormat:@"单笔限额%ldW",zDan1];
        NSInteger dan2 = [[[zBankDic objectForKey:@"Boss"] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDan2 = dan2/10000;
        xian3.text = [NSString stringWithFormat:@"每日限额%ldW",zDan2];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (SCREEN_WIDTH == 320) {
            btn.frame = CGRectMake(10,xian1.bottom+5, 95, 35);
        }
        [btn.layer setBorderWidth:1.0f];
        [btn.layer setBorderColor:[UIColor grayColor].CGColor];
        [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:[[zBankDic objectForKey:@"Boss"] objectForKey:@"LogoPath"]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
        [_zScrollView addSubview:btn];
        btn.tag = 700;
        _zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*1.1);
//        downBtn.frame = CGRectMake(10, btn.bottom+20, SCREEN_WIDTH-20, 43);
        pView.frame = CGRectMake(10, btn.bottom+20, SCREEN_WIDTH-20, 133);

    }else{
        NSInteger dan1 = [[[zBankDic objectForKey:@"Boss"] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDan1 = dan1/10000;
        xian1.text = [NSString stringWithFormat:@"单笔限额%ldW",zDan1];
        NSInteger dan2 = [[[zBankDic objectForKey:@"Boss"] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDan2 = dan2/10000;
        xian3.text = [NSString stringWithFormat:@"每日限额%ldW",zDan2];


        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (SCREEN_WIDTH == 320) {
            btn.frame = CGRectMake(10,xian1.bottom+5, 95, 35);
        }
        [btn.layer setBorderWidth:1.0f];
        [btn.layer setBorderColor:[UIColor grayColor].CGColor];
        [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:[[zBankDic objectForKey:@"Boss"] objectForKey:@"LogoPath"]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
        [_zScrollView addSubview:btn];
        btn.tag = 700;
        UILabel *xian2 = [[UILabel alloc]initWithFrame:CGRectMake(10, btn.bottom+5, 120, 20)];
        NSInteger dan = [[[[zBankDic objectForKey:@"Common"] objectAtIndex:0] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDan = dan/10000;
        xian2.text = [NSString stringWithFormat:@"单笔限额%ldW",(long)zDan];
        xian2.textColor  = [UIColor grayColor];
        xian2.textAlignment = NSTextAlignmentLeft;
        xian2.font = [UIFont systemFontOfSize:12];
        [_zScrollView addSubview:xian2];
        
        
        UILabel *xian4 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-160, btn.bottom+5, 150, 20)];
        NSInteger day = [[[[zBankDic objectForKey:@"Common"] objectAtIndex:0] objectForKey:@"SingleLimit"] integerValue];
        NSInteger zDay = day/10000;
        xian4.text = [NSString stringWithFormat:@"每日限额%ldW",zDay];
        xian4.textColor  = [UIColor grayColor];
        xian4.textAlignment = NSTextAlignmentRight;
        xian4.font = [UIFont systemFontOfSize:12];
        [_zScrollView addSubview:xian4];
        
        [zBankList removeObjectAtIndex:0];
        NSLog(@"%@",[zBankDic objectForKey:@"Common"]);
        btnTag = 0;
        NSInteger zCount = [[zBankDic objectForKey:@"Common"] count]/3;
        NSLog(@"%lu",[[zBankDic objectForKey:@"Common"] count]%3);
        if (([[zBankDic objectForKey:@"Common"] count]%3) != 0) {
            zCount += 1;
        }
        NSLog(@"%ld",zCount);
        for (int i = 0; i< zCount; i++) {
            for (int j = 0; j < 3; j++) {
                NSLog(@"%d",btnTag);
                NSLog(@"%lu",(unsigned long)[[zBankDic objectForKey:@"Common"] count]);
                
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                if (SCREEN_WIDTH == 320) {
                    btn.frame = CGRectMake(10+102.5*j,xian2.bottom+5+i*40 , 95, 35);
                }
                [btn.layer setBorderWidth:1.0f];
                [btn.layer setBorderColor:[UIColor grayColor].CGColor];
                
                [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:[[[zBankDic objectForKey:@"Common"] objectAtIndex:btnTag] objectForKey:@"LogoPath"]] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
                [_zScrollView addSubview:btn];
                btn.tag = btnTag+701;
                btnTag++;
                if (btnTag == [[zBankDic objectForKey:@"Common"] count]) {
                    break;
                }
            }
        }
     
        pView.frame = CGRectMake(10, xian2.bottom+5+(zCount)*40+20, SCREEN_WIDTH-20, 133);
        _zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*1.5);

    }
     */
    
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if ([textField isEqual:_phoneNumber]||[textField isEqual:_passwd]) {
        [UIView animateWithDuration:0.3f animations:^{
            CGRect curFrame=CGRectMake(0, -200, self.view.width, self.view.height);
            self.view.frame=curFrame;
        }];
    }
    return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
-(BOOL)alertShow{

    if (_bangdin.zBankText.text.length<=0 || _bangdin.zBankText.text==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请输入银行卡号" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_bangdin.zName.text.length<=0 || _bangdin.zName.text==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请输入账户姓名" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_bangdin.zProvince.titleLabel.text.length<=0 || [_bangdin.zProvince.titleLabel.text isEqualToString:@"开户行所在的省"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请选择开户行所在的省" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_bangdin.zCity.titleLabel.text.length<=0 || [_bangdin.zCity.titleLabel.text isEqualToString:@"开户行所在的市"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请选择开户行所在的市" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_bangdin.zBankType.titleLabel.text.length<=0 || _bangdin.zBankType.titleLabel.text==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请选择开户证件类型" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_bangdin.zDocumentsNumber.text.length<=0 || _bangdin.zDocumentsNumber.text==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请输入证件号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
       return NO;
    }
    if ([zBackID isEqualToString:@"0"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择银行卡" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (_phoneNumber.text.length<=0 ||_phoneNumber.text==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请输入绑定手机号" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    return YES;
}
#pragma mark - 获取验证码
static int i = 60;
-(void)clickRBtn:(UIButton *)sender{


    if ([self alertShow] == YES) {

    //获取验证码
        [GMDCircleLoader setOnView:self.view withTitle:@"获取验证码···" animated:YES];
        UITextField *text1 = (UITextField *)[self.view viewWithTag:500];
//        UITextField *text3 = (UITextField *)[self.view viewWithTag:502];
        NSString *userid   = [[NSUserDefaults standardUserDefaults] objectForKey:@"userID"];
        NSMutableDictionary *  smallGoodsDic = [NSMutableDictionary dictionaryWithCapacity:1];
        [smallGoodsDic setObject:userid forKey:@"AgentID"];
        [smallGoodsDic setObject:zBackID forKey:@"BankID"];
//        [smallGoodsDic setObject:text3.text forKey:@"BankBranch"];
        [smallGoodsDic setObject:text1.text forKey:@"CardNumber"];
        [smallGoodsDic setObject:zPID forKey:@"ProvinceID"];
        [smallGoodsDic setObject:zCID forKey:@"CityID"];
        [smallGoodsDic setObject:_phoneNumber.text forKey:@"MobileNumber"];
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:smallGoodsDic options:NSJSONWritingPrettyPrinted error:nil];
        NSString *jsonString = [jsonData base64EncodedStringWithOptions:0];
        NSString *str = [self encodeString:jsonString :@"hotkeycuk"];
        NSDictionary *paramer = @{@"sign":str};

        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
        [manager POST:@"http://api.dw521.com/api/profile/sendcode.php" parameters:paramer success:^(AFHTTPRequestOperation *operation, id responseObject) {
             [GMDCircleLoader hideFromView:self.view animated:YES];
            NSString *str = responseObject[@"sign"];
            EncryptionData *data = [[EncryptionData alloc]init];
            NSString *datastr = [data decryption:str :PasswordKey];
            NSData* dataFromString = [datastr dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *dataDic = [NSJSONSerialization  JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:nil];
            
            NSLog(@"获取验证码返回结果== %@",dataDic);
            if ([dataDic[@"status"] isEqualToString:@"failed"]) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:dataDic[@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
            } else{
                sender.hidden = YES;
                _timeLabel.hidden = NO;
                NSDictionary *myDic = dataDic[@"data"];
                self.merOrderId = [NSString stringWithFormat:@"%@",myDic[@"merOrderId"]];
                self.phoneNo = [NSString stringWithFormat:@"%@",myDic[@"phoneNo"]];
                self.phoneToken = [NSString stringWithFormat:@"%@",myDic[@"phoneToken"]];
                zTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
                _timeLabel.text = @"重新获取验证码60";
                i = 60;
            }
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [GMDCircleLoader hideFromView:self.view animated:YES];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            
        }];

    UIButton *sendCodeButton = (UIButton *)[self.view viewWithTag:100];
    [sendCodeButton setBackgroundImage:[UIImage imageNamed:@"sendnum1"] forState:UIControlStateSelected];
    }
}
-(void)updateTime{
    i--;
    _timeLabel.text = [NSString stringWithFormat:@"重新发送验证码%d",i];
    if (i == 0) {
        _getPasswordBut.hidden = NO;
        [zTimer invalidate];
        zTimer = nil;
        _timeLabel.hidden = YES;
    }
}
#pragma mark - 加密
-(NSString *)encodeString:(NSString *)data :(NSString *)key{
    //    NSData* sampleData = [data dataUsingEncoding:NSUTF8StringEncoding];
    //
    //    NSString * base64String = [sampleData base64EncodedStringWithOptions:0];
    NSLog(@"%@",data);
    NSString *result=[[NSMutableString alloc] init];
    NSInteger keyLength = [key length];
    int position = 0;
    int keyChar = 0;
    int strChar = 0;
    for (int i = 0; i < [data length]; i++) {
        position = i % keyLength;
        strChar = [data characterAtIndex:i];
        keyChar =[key characterAtIndex:position];
        int  ch = strChar ^ keyChar;
        char ca = (char) ch;
        result=[result stringByAppendingString:[NSString stringWithFormat:@"%C",ca]];
    }
    
    NSData* sampleDat1a = [result dataUsingEncoding:NSUTF8StringEncoding];
    
    NSString * base64String1 = [sampleDat1a base64EncodedStringWithOptions:0];
    
    return base64String1;
}
-(void)singleTap1{
    self.tabBarController.tabBar.hidden = NO;
    _picker.hidden = YES;
    UITextField *text1 = (UITextField *)[self.view viewWithTag:500];
    UITextField *text2 = (UITextField *)[self.view viewWithTag:501];
    UITextField *text3 = (UITextField *)[self.view viewWithTag:502];
    UITextField *text4 = (UITextField *)[self.view viewWithTag:503];
    [text1 resignFirstResponder];
    [text2 resignFirstResponder];
    [text3 resignFirstResponder];
    [text4 resignFirstResponder];
    [_passwd resignFirstResponder];
    [_phoneNumber resignFirstResponder];
    zPickerBtn.hidden = YES;
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curFrame=CGRectMake(0, 0, self.view.width, self.view.height);
        self.view.frame=curFrame;
    }];
}
#pragma mark - 点击事件
-(void)clickType:(UIButton *)sender{
    self.tabBarController.tabBar.hidden = YES;

    UITextField *text1 = (UITextField *)[self.view viewWithTag:500];
    UITextField *text2 = (UITextField *)[self.view viewWithTag:501];
    UITextField *text3 = (UITextField *)[self.view viewWithTag:502];
    UITextField *text4 = (UITextField *)[self.view viewWithTag:503];
    [text1 resignFirstResponder];
    [text2 resignFirstResponder];
    [text3 resignFirstResponder];
    [text4 resignFirstResponder];
    [_passwd resignFirstResponder];
    [_phoneNumber resignFirstResponder];
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curFrame=CGRectMake(0, 0, self.view.width, self.view.height);
        self.view.frame=curFrame;
    }];
    if (sender.tag == 400)
    //账户类型
    {
        
    }else if (sender.tag == 401){
    if (_picker) {
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainBackProvince];

        
    }else
    //开户行所在的省
    {
        zArrayData = [[NSMutableArray alloc]init];
        
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainBackProvince];
        
        
//        zTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,SCREEN_HEIGHT - 180, SCREEN_WIDTH,200)];
//        //zTableView.backgroundColor = [UIColor redColor];
//        zTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//        zTableView.delegate = self;
//        zTableView.dataSource = self;
//        zTableView.bounces = YES;
//        [self.view addSubview:zTableView];
        
        

        zIndex = 0;
        
        //创建省市区选择框
        _picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 180, SCREEN_WIDTH, 200)];
        _picker.backgroundColor = LineColor;
        _picker.layer.borderColor = BackColor.CGColor;
        _picker.layer.borderWidth = 1.0;
        _picker.dataSource = self;
        _picker.delegate = self;
        _picker.hidden = NO;
        _picker.showsSelectionIndicator = NO;
        [self.view addSubview:_picker];
        
        if (zPickerBtn) {
            zPickerBtn.hidden = NO;
        }else{
        zPickerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [zPickerBtn setBackgroundColor:[UIColor blackColor]];
        zPickerBtn.alpha = 0.4;
        zPickerBtn.frame = CGRectMake(0, SCREEN_HEIGHT - 103, SCREEN_WIDTH, 26);
        [zPickerBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:zPickerBtn];
        }
        _select = 0;
        
        UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap1)];
        [singleTapGestureRecognizer setNumberOfTapsRequired:1];
        [self.view addGestureRecognizer:singleTapGestureRecognizer];
    

    }
    }else if (sender.tag == 402)
    //开户行所在的市
    {
        
        if ([zPID isEqualToString:@"0"]) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择省" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }else{
            zCityIndex = 0;

            YoungAllData *data = [[YoungAllData alloc]init];
            data.delegate=self;
            [data gainBackCity:zPID];
            _select = 1;
        }

    }else if (sender.tag == 403)
    //开户证件类型
    {
        zZhengJianIndex = 0;
        zPickerBtn.hidden = NO;
        _select = 2;
        zArrayData = [[NSMutableArray alloc]initWithObjects:@"身份证号", nil];
        if (_picker) {
            _picker.hidden = NO;
            [_picker reloadAllComponents];

        }else{
            _picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 180, SCREEN_WIDTH, 200)];
            _picker.backgroundColor = LineColor;
            _picker.layer.borderColor = BackColor.CGColor;
            _picker.layer.borderWidth = 1.0;
            _picker.dataSource = self;
            _picker.delegate = self;
            _picker.hidden = NO;
            [self.view addSubview:_picker];
            
        }
        if (zPickerBtn) {
            zPickerBtn.hidden = NO;
        }else{
            zPickerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [zPickerBtn setBackgroundColor:[UIColor blackColor]];
            zPickerBtn.alpha = 0.4;
            zPickerBtn.frame = CGRectMake(0, SCREEN_HEIGHT - 103, SCREEN_WIDTH, 26);
            [zPickerBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:zPickerBtn];
        }

    }
}

#pragma mark - UIpickerView 选择Btn
-(void)clickBtn{
    self.tabBarController.tabBar.hidden = NO;

        UIButton *btn = (UIButton *)[self.view viewWithTag:401];
        UIButton *btn1 = (UIButton *)[self.view viewWithTag:402];
        UIButton *btn2 = (UIButton *)[self.view viewWithTag:403];
        switch (_select) {
            case Province://选择省
                //[_addressView.provinceBut setTitle:pickerArray[row] forState:UIControlStateNormal];
                zProvinceIndex = zIndex;
                [btn setTitle:[[zArrayData objectAtIndex:zIndex] objectForKey:@"ProvinceName"] forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                zPID =[NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:zIndex] objectForKey:@"BankProvinceID"]];
                _picker.hidden = YES;
                [btn1 setTitle:@"开户行所在的市" forState:UIControlStateNormal];
                [btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                zCID = @"0";
                break;
    
            case City://市
                //[_addressView.cityBut setTitle:pickerArray[row] forState:UIControlStateNormal];
                [btn1 setTitle:[[zArrayData objectAtIndex:zCityIndex] objectForKey:@"CityName"] forState:UIControlStateNormal];
                [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
                zCID = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:zCityIndex] objectForKey:@"BankCityID"]];
                _picker.hidden = YES;
    
    
                break;
            case Qu://市
                //[_addressView.cityBut setTitle:pickerArray[row] forState:UIControlStateNormal];
                [btn2 setTitle:[zArrayData objectAtIndex:zZhengJianIndex] forState:UIControlStateNormal];
                [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
                _picker.hidden = YES;
                
                
                break;
    
            }
    zPickerBtn.hidden = YES;
}
#pragma mark - 省回调
-(void)bankProvince:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    _picker.hidden = NO;
    _select = 0;
    NSLog(@"%@",sign);
    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [_picker reloadAllComponents];
    if (zProvinceIndex==0) {
        [_picker selectRow:0 inComponent:0 animated:NO];
    }else{
        [_picker selectRow:zProvinceIndex inComponent:0 animated:NO];
    }
    zPickerBtn.hidden = NO;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma mark - 绑定回调失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark -市回调
-(void)bankCity:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [_picker reloadAllComponents];
    _picker.hidden = NO;
    if (zCityIndex==0) {
        [_picker selectRow:0 inComponent:0 animated:NO];
    }else{
        [_picker selectRow:zCityIndex inComponent:0 animated:NO];
    }
    zPickerBtn.hidden = NO;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma -mark UIPickerView 的代理

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [zArrayData count];
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    UIButton *btn = (UIButton *)[self.view viewWithTag:401];
    UIButton *btn1 = (UIButton *)[self.view viewWithTag:402];
    UIButton *btn2 = (UIButton *)[self.view viewWithTag:403];
    if (_select == 0) {
        if (row == 0) {
            [btn setTitle:[[zArrayData objectAtIndex:zProvinceIndex] objectForKey:@"ProvinceName"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            zPID =[NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:zProvinceIndex] objectForKey:@"BankProvinceID"]];

        }
        return [[zArrayData objectAtIndex:row]objectForKey:@"ProvinceName"];
        
    }else if (_select == 1){
        if (row == 0) {
            [btn1 setTitle:[[zArrayData objectAtIndex:zCityIndex] objectForKey:@"CityName"] forState:UIControlStateNormal];
            [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            zCID = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:zCityIndex] objectForKey:@"BankCityID"]];

        }
        return [[zArrayData objectAtIndex:row]objectForKey:@"CityName"];
        
    }else{
        if (row == 0) {
            [btn2 setTitle:[zArrayData objectAtIndex:0] forState:UIControlStateNormal];
            [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
        return [zArrayData objectAtIndex:row];
        
    }
}

#pragma -mark 选中省市区的代理

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"%ld",row);
    if (_select == 0) {
        zIndex = row;
    }else if (_select == 1){
        zCityIndex = row;
    }
    
}


#pragma mark - 立即绑定
-(void)clickBang{
    [_passwd resignFirstResponder];
    [_phoneNumber resignFirstResponder];
    [UIView animateWithDuration:0.3f animations:^{
        CGRect curFrame=CGRectMake(0, 0, self.view.width, self.view.height);
        self.view.frame=curFrame;
    }];
    if ([self alertShow] == YES) {
        if (_passwd.text.length <=0 ||_passwd.text == nil) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入验证吗" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            return;
        }
        if (self.merOrderId == nil||self.merOrderId.length<=0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请先获取验证码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }else{
            [_passwd resignFirstResponder];
        UITextField *text1 = (UITextField *)[self.view viewWithTag:500];
        UITextField *text3 = (UITextField *)[self.view viewWithTag:502];
        [GMDCircleLoader setOnView:self.view withTitle:@"绑定中···" animated:YES];
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=  self;
        [data binding:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"]  andBankID:zBackID andBankBranch:text3.text  andCardNumber:text1.text andProvinceID:zPID andCityID:zCID merOrderId:self.merOrderId phoneNo:self.phoneNo phoneToken:self.phoneToken mobileNumber:_phoneNumber.text code:_passwd.text];
        }
    }

}
#pragma mark - binding 回调
-(void)bind:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    [self initAlert];
    [[NSUserDefaults standardUserDefaults]setValue:@"1" forKey:@"IsBindBankcard"];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

#pragma mark - initAlert
-(void)initAlert{
    //两种情况 success fail
    if (/* DISABLES CODE */ (1)) {
        //
        views = [[UIView alloc]init];
        views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        views.userInteractionEnabled = YES;
        views.backgroundColor = [UIColor blackColor];
        views.alpha = 0.4;
        [self.view addSubview:views];
        
        alertView = [[UIView alloc]initWithFrame:CGRectMake(60, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-120, 120)];
        alertView.backgroundColor = [UIColor whiteColor];
        alertView.userInteractionEnabled = YES; 
        alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
        [self.view addSubview:alertView];
        
        UIImageView *duiImage = [[UIImageView alloc]initWithFrame:CGRectMake(alertView.frame.size.width/2-42, 37, 20, 23)];
        [duiImage setImage:[UIImage imageNamed:@"订单完成_03"]];
        [alertView addSubview:duiImage];
        
        UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(duiImage.right, 30, 64, 40)];
        alertLabel.text = @"验证成功";
        alertLabel.numberOfLines = 0;
        alertLabel.textColor = [UIColor blackColor];
        alertLabel.font = [UIFont systemFontOfSize:16];
        alertLabel.textAlignment = NSTextAlignmentLeft;
        [alertView addSubview:alertLabel];
        
        
        //
        UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        leftBtn.frame = CGRectMake(0, alertLabel.bottom+32, alertView.frame.size.width, 28);
        UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
        CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
        maskLayer1.frame = leftBtn.bounds;
        maskLayer1.path = maskPath1.CGPath;
        leftBtn.layer.mask = maskLayer1;
        
        [leftBtn addTarget:self action:@selector(cliclRight) forControlEvents:UIControlEventTouchUpInside];
        [leftBtn setImage:[UIImage imageNamed:@"下线订单---弹窗_07"] forState:UIControlStateNormal];
        [leftBtn setImage:[UIImage imageNamed:@"下线订单---弹窗_07"] forState:UIControlStateHighlighted];
        [alertView addSubview:leftBtn];

    }else{
    views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    views.userInteractionEnabled = YES;
    views.backgroundColor = [UIColor blackColor];
    views.alpha = 0.4;
    [self.view addSubview:views];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(60, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-120, 120)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [self.view addSubview:alertView];
    
    UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 30, alertView.frame.size.width-40, 40)];
    alertLabel.text = @"您输入的信息有误\n请核对信息";
    alertLabel.numberOfLines = 0;
    alertLabel.textColor = [UIColor blackColor];
    alertLabel.font = [UIFont systemFontOfSize:14];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:alertLabel];
    
    
    //
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, alertLabel.bottom+32, alertView.frame.size.width, 28);
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    
    [leftBtn addTarget:self action:@selector(cliclRight) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setImage:[UIImage imageNamed:@"下线订单---弹窗_07"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"下线订单---弹窗_07"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];
    }
}
#pragma mark 确定按钮
-(void)cliclRight{
    [views removeFromSuperview];
    views = nil;
    [alertView removeFromSuperview];
    alertView = nil;
    

    if ([[self.controller class] isSubclassOfClass:[LoginViewController class]]) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        MainLineViewController *mainBar = storyboard.instantiateInitialViewController;
        [[[UIApplication sharedApplication] delegate] window] .rootViewController =mainBar;
    }else{
               FinishWithDrawViewController *finish = [[FinishWithDrawViewController alloc]init];
               finish.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:finish animated:YES];
    }

}
#pragma mark - 选择银行
-(void)clickUser:(UIButton *)sender{
    for (int i = 0 ; i <= [[zBankDic objectForKey:@"Common"] count]; i++) {
        UIButton *btn = (UIButton *)[self.view viewWithTag:i+700];
        [btn.layer setBorderWidth:1.0f];
        [btn.layer setBorderColor:[UIColor grayColor].CGColor];
    }
    
    NSLog(@"%ld",(long)sender.tag);
    UIButton *btn = (UIButton *)[self.view viewWithTag:sender.tag];
    [btn.layer setBorderWidth:1.0f];
    [btn.layer setBorderColor:[UIColor redColor].CGColor];
  
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"LevelID"] isEqualToString:@"1"]) {
    zBackID = [NSString stringWithFormat:@"%@",[[zBankDic objectForKey:@"Boss"] objectForKey:@"BankID"] ];
    }else{
        if (sender.tag == 700) {
            zBackID =[NSString stringWithFormat:@"%@",[[zBankDic objectForKey:@"Boss"]  objectForKey:@"BankID"] ];
        }else{
            zBackID = [NSString stringWithFormat:@"%@",[[[zBankDic objectForKey:@"Common"] objectAtIndex:(sender.tag-701)] objectForKey:@"BankID"] ];
        }
    }
    
}

#pragma mark - 用户协议
-(void)clickUserBtn{
    UserProtocolViewController *userProtocol = [[UserProtocolViewController alloc]init];
    [self.navigationController pushViewController:userProtocol animated:YES];
}
#pragma mark - UItextfield delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [textField resignFirstResponder];
    
    return  YES;
}
#pragma mark - 返回
-(void)backGo{
    if ([isWhere isEqualToString:@"1"]) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
